package com.changxu.wc;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class WordCountMapper extends Mapper<LongWritable, Text,WordCountBean, NullWritable> {

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
//      将读取的文本数据保存到bean对象中
        WordCountBean bean = new WordCountBean();
//        默认将id设置为1，防止传输时报空指针错误
        bean.setId(1);
        bean.setNumber(Integer.parseInt(value.toString()));
        context.write(bean, NullWritable.get());

    }
}
